home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / PowerPlant / CGI++ Framework / Support Classes / LCGIApplication.cp next >
Encoding:
Text File  |  1995-11-17  |  7.9 KB  |  229 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    LCGIApplication.cp                     ©1995 Brian Todoroff All rights reserved.
  3. // ===========================================================================
  4. //
  5. //  Commercial or for-profit use subject to licence.  Contact btodorof@hmc.edu.
  6. //
  7. //    This class may only be distributed with the complete CGI++ Framework
  8. //  package.  For further information contact the author at btodorof@hmc.edu.
  9. //
  10. //    This file contains the code for a PowerPlant application class which
  11. //  supports the CGI inteface provided by WebSTAR and MacHTTP.
  12. //
  13. #include "LCGIApplication.h"
  14.  
  15. // ---------------------------------------------------------------------------
  16. //        • LCGIApplication             // replace this with your App type
  17. // ---------------------------------------------------------------------------
  18. //    Constructor
  19.  
  20. LCGIApplication::LCGIApplication()
  21. {
  22. }
  23.  
  24.  
  25. // ---------------------------------------------------------------------------
  26. //        • ~LCGIApplication            // replace this with your App type
  27. // ---------------------------------------------------------------------------
  28. //    Destructor
  29. //
  30.  
  31. LCGIApplication::~LCGIApplication()
  32. {
  33. }
  34.  
  35. // ---------------------------------------------------------------------------
  36. //        • StartUp
  37. // ---------------------------------------------------------------------------
  38. //    This function lets you do something when the application starts up. 
  39. //    For example, you could issue your own new command, or respond to a system
  40. //  oDoc (open document) event.
  41.  
  42. void
  43. LCGIApplication::StartUp()
  44. {
  45. }
  46.  
  47. // ---------------------------------------------------------------------------
  48. //        • ObeyCommand
  49. // ---------------------------------------------------------------------------
  50. //    Respond to commands
  51.  
  52. Boolean
  53. LCGIApplication::ObeyCommand(
  54.     CommandT    inCommand,
  55.     void        *ioParam)
  56. {
  57.     return LApplication::ObeyCommand(inCommand, ioParam);
  58. }
  59.  
  60. // ---------------------------------------------------------------------------
  61. //        • FindCommandStatus
  62. // ---------------------------------------------------------------------------
  63. //    This function enables menu commands.
  64. //
  65.  
  66. void
  67. LCGIApplication::FindCommandStatus(
  68.     CommandT    inCommand,
  69.     Boolean        &outEnabled,
  70.     Boolean        &outUsesMark,
  71.     Char16        &outMark,
  72.     Str255        outName)
  73. {
  74.     LApplication::FindCommandStatus(inCommand, outEnabled, outUsesMark, outMark, outName);
  75. }
  76.  
  77. // ===========================================================================
  78. // • Apple Event Handlers                                Apple Event Handlers •
  79. // ===========================================================================
  80.  
  81. void
  82. LCGIApplication::HandleAppleEvent(
  83.     const AppleEvent    &inAppleEvent,
  84.     AppleEvent            &outAEReply,
  85.     AEDesc                &outResult,
  86.     long                inAENumber)
  87. {
  88.     StAEDescriptor    targD;
  89.     LCHandleStream    SData;
  90.     CGIData            theData;
  91.     int             count;
  92.  
  93.     switch (inAENumber) {
  94.     
  95.         case 7000:
  96.             SData<<"Detected 'WWW' event, type 'srch'"<<endl;
  97.             SData<<"Please update your copy of MacHTTP."<<endl;
  98.             targD.GetOptionalParamDesc(inAppleEvent, '----', typeWildCard);
  99.             break;
  100.  
  101.         case 7002:
  102.             // Detected WWW event, type sdoc, #7002
  103.             targD.GetOptionalParamDesc(inAppleEvent, '----', typeWildCard);
  104.             count=GetHandleSize(targD.mDesc.dataHandle);
  105.             theData.direct=new char[count+1];
  106.             memcpy(theData.direct,*targD.mDesc.dataHandle,count);
  107.             theData.direct[count]=0x00;
  108.             
  109.             targD.GetOptionalParamDesc(inAppleEvent, 'kfor', typeWildCard);
  110.             count=GetHandleSize(targD.mDesc.dataHandle);
  111.             theData.search=new char[count+1];
  112.             memcpy(theData.search,*targD.mDesc.dataHandle,count);
  113.             theData.search[count]=0x00;
  114.  
  115.             targD.GetOptionalParamDesc(inAppleEvent, 'user', typeWildCard);
  116.             count=GetHandleSize(targD.mDesc.dataHandle);
  117.             theData.uname=new char[count+1];
  118.             memcpy(theData.uname,*targD.mDesc.dataHandle,count);
  119.             theData.uname[count]=0x00;
  120.  
  121.             targD.GetOptionalParamDesc(inAppleEvent, 'pass', typeWildCard);
  122.             count=GetHandleSize(targD.mDesc.dataHandle);
  123.             theData.pass=new char[count+1];
  124.             memcpy(theData.pass,*targD.mDesc.dataHandle,count);
  125.             theData.pass[count]=0x00;
  126.  
  127.             targD.GetOptionalParamDesc(inAppleEvent, 'frmu', typeWildCard);
  128.             count=GetHandleSize(targD.mDesc.dataHandle);
  129.             theData.fromuser=new char[count+1];
  130.             memcpy(theData.fromuser,*targD.mDesc.dataHandle,count);
  131.             theData.fromuser[count]=0x00;
  132.  
  133.             targD.GetOptionalParamDesc(inAppleEvent, 'addr', typeWildCard);
  134.             count=GetHandleSize(targD.mDesc.dataHandle);
  135.             theData.caddr=new char[count+1];
  136.             memcpy(theData.caddr,*targD.mDesc.dataHandle,count);
  137.             theData.caddr[count]=0x00;
  138.  
  139.             targD.GetOptionalParamDesc(inAppleEvent, 'post', typeWildCard);
  140.             count=GetHandleSize(targD.mDesc.dataHandle);
  141.             theData.post=new char[count+1];
  142.             memcpy(theData.post,*targD.mDesc.dataHandle,count);
  143.             theData.post[count]=0x00;
  144.  
  145.             targD.GetOptionalParamDesc(inAppleEvent, 'meth', typeWildCard);
  146.             count=GetHandleSize(targD.mDesc.dataHandle);
  147.             theData.method=new char[count+1];
  148.             memcpy(theData.method,*targD.mDesc.dataHandle,count);
  149.             theData.method[count]=0x00;
  150.  
  151.             targD.GetOptionalParamDesc(inAppleEvent, 'svnm', typeWildCard);
  152.             count=GetHandleSize(targD.mDesc.dataHandle);
  153.             theData.sname=new char[count+1];
  154.             memcpy(theData.sname,*targD.mDesc.dataHandle,count);
  155.             theData.sname[count]=0x00;
  156.  
  157.             targD.GetOptionalParamDesc(inAppleEvent, 'svpt', typeWildCard);
  158.             count=GetHandleSize(targD.mDesc.dataHandle);
  159.             theData.sport=new char[count+1];
  160.             memcpy(theData.sport,*targD.mDesc.dataHandle,count);
  161.             theData.sport[count]=0x00;
  162.  
  163.             targD.GetOptionalParamDesc(inAppleEvent, 'scnm', typeWildCard);
  164.             count=GetHandleSize(targD.mDesc.dataHandle);
  165.             theData.cginame=new char[count+1];
  166.             memcpy(theData.cginame,*targD.mDesc.dataHandle,count);
  167.             theData.cginame[count]=0x00;
  168.  
  169.             targD.GetOptionalParamDesc(inAppleEvent, 'ctyp', typeWildCard);
  170.             count=GetHandleSize(targD.mDesc.dataHandle);
  171.             theData.ctype=new char[count+1];
  172.             memcpy(theData.ctype,*targD.mDesc.dataHandle,count);
  173.             theData.ctype[count]=0x00;
  174.  
  175.             targD.GetOptionalParamDesc(inAppleEvent, 'refr', typeWildCard);
  176.             count=GetHandleSize(targD.mDesc.dataHandle);
  177.             theData.referer=new char[count+1];
  178.             memcpy(theData.referer,*targD.mDesc.dataHandle,count);
  179.             theData.referer[count]=0x00;
  180.  
  181.             targD.GetOptionalParamDesc(inAppleEvent, 'Agnt', typeWildCard);
  182.             count=GetHandleSize(targD.mDesc.dataHandle);
  183.             theData.agent=new char[count+1];
  184.             memcpy(theData.agent,*targD.mDesc.dataHandle,count);
  185.             theData.agent[count]=0x00;
  186.  
  187.             outResult.descriptorType='TEXT';
  188.             HandleCGICall(theData,SData);
  189.             outResult.dataHandle = SData.DetachDataHandle();
  190.             break;
  191.             
  192.         default:
  193.             LApplication::HandleAppleEvent(inAppleEvent, outAEReply,
  194.                                 outResult, inAENumber);
  195.             break;
  196.     }
  197. }
  198.  
  199. void LCGIApplication::HandleCGICall(struct CGIData &data,LCHandleStream &sout)
  200. {
  201.     sout<<"This is comming from HandleCGICall in LCGIApplication"<<endl;
  202.     sout<<"You need to make a sub-class of CCGIApp and"<<endl;
  203.     sout<<"override the HandleCGICall method.  See the <CGI Starter App>"<<endl;
  204.     sout<<"code for more information."<<endl<<endl;
  205.     sout<<"The data recived is "<<endl;
  206.     sout<<"direct:    "<<data.direct<<endl;        //direct parameter
  207.     sout<<"search:    "<<data.search<<endl;        //search parameters
  208.     sout<<"uname:    "<<data.uname<<endl;        //current user name
  209.     sout<<"pass:    "<<data.pass<<endl;            //current user password
  210.     sout<<"fromuser:"<<data.fromuser<<endl;        //
  211.     sout<<"caddr:   "<<data.caddr<<endl;        //client ip address
  212.     sout<<"post:    "<<data.post<<endl;            //post parameters
  213.     sout<<"method:    "<<data.method<<endl;        //method (post or get)
  214.     sout<<"sname:   "<<data.sname<<endl;        //server name
  215.     sout<<"sport:   "<<data.sport<<endl;        //server port
  216.     sout<<"cginame: "<<data.cginame<<endl;        //cgi name as called
  217.     sout<<"ctype:   "<<data.ctype<<endl;        //content type
  218.     sout<<"referer: "<<data.referer<<endl;        //referer
  219.     sout<<"agent:   "<<data.agent<<endl;        //client agent program
  220.     sout<<endl;
  221.     sout<<"<H3>That's It For Now!</H3>"<<endl;
  222.     sout<<endl<<"Based on the CGI++ Framework for PowerPlant"<<endl;
  223.     sout<<"Contact the author at btodorof@hmc.edu"<<endl;
  224.     sout<<"Bug reports and suggestions appreciated."<<endl;
  225.     return;
  226. }
  227.     
  228.  
  229.